package com.yaoxuguang.concurrence.wait_notify.producer_consumer.ontToOne;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.wait_notify.producer_consumer.ontToOne
 * @Description: 消费者
 * @date 2018年12月21日18:02
 */
public class Consumer {
    private String lock;

    public Consumer(String lock) {
        this.lock = lock;
    }

    public void getValue(){
        try {
            synchronized (lock){
                if(ValueObject.value.equals("")){
                    lock.wait();
                }
                System.out.println("消费者获取到的值："+ValueObject.value);
                ValueObject.value ="";
                lock.notify();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
